﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SysContext;

namespace DataAccessLayer
{
    public class UserTable
    {
        SysDataContext Data = new SysDataContext();
        public int RowcountUser(string name, string pass)
        {
            int count = (from i in Data.Users
                         where i.Username == name && i.Password == pass
                         select i).Count();
            return count;
        }
        public List<User> SelectUserAll()
        {
            var p = (from i in Data.Users
                     select i).ToList();
            return p.ToList();
        }
        /// <summary>
        /// Tìm ID cua User
        /// </summary>
        /// <param name="ik"> Id là ID </param>
        /// <returns></returns>
        public double GetID(string name)
        {
            User myUser = SelectUserAll().Single(p => p.Username == name);
            return myUser.Id;
        }

        public double GetID()
        {
            return SelectUserAll().Max(p => p.Id);
        }
        

        //Inser User
        public void InsertUser(string Username, string Password, string Mail)
        {
            Data.Insertuser(Username, Password, Mail);
        }
    }
}
